package com.bdqn.ch03thymeleaf.utils;

import redis.clients.jedis.Jedis;

//Redis的工具类
public class RedisUtil {
    public static Jedis redisConnection() {
        Jedis jedis = new Jedis("localhost",6379);
        return jedis;
    }


    public String setKey(String key, String value) {
        return RedisUtil.redisConnection().set(key, value);
    }


    public String setKey(String key, String value, int expire) {
        return RedisUtil.redisConnection().setex(key, expire, value);
    }


    public String getKey(String key) {
        return RedisUtil.redisConnection().get(key);
    }

    public long getTtl(String key) {
        return RedisUtil.redisConnection().ttl(key);
    }

    public long deleteKey(String key) {
        return RedisUtil.redisConnection().del(key);
    }
}
